package cn.edu.qfnu.oj.entity;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

@Entity
@DynamicUpdate
public class Message implements Serializable {

    private int id;  //消息ID
    private String title; //消息标题
    private String content; // 消息内容
    private String sendFrom; // 消息来源
    private String sendTo; //消息送至
    private LocalDateTime sendTime;  //发送时间
    private LocalDateTime viewTime; //查看时间
    private Boolean isViewed;  //是否查看

    public Message() {}

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Column(name = "title", length = 16)
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column(name = "content", length = 64)
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Column(name = "send_from", length = 16)
    public String getSendFrom() {
        return sendFrom;
    }

    public void setSendFrom(String sendFrom) {
        this.sendFrom = sendFrom;
    }

    @Column(name = "send_to", length = 16)
    public String getSendTo() {
        return sendTo;
    }

    public void setSendTo(String sendTo) {
        this.sendTo = sendTo;
    }

    @Column(name = "send_time")
    public LocalDateTime getSendTime() {
        return sendTime;
    }

    public void setSendTime(LocalDateTime sendTime) {
        this.sendTime = sendTime;
    }

    @Column(name = "view_time")
    public LocalDateTime getViewTime() {
        return viewTime;
    }

    public void setViewTime(LocalDateTime viewTime) {
        this.viewTime = viewTime;
    }

    @Column(name = "is_viewed")
    public Boolean getViewed() {
        return isViewed;
    }

    public void setViewed(Boolean viewed) {
        isViewed = viewed;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass()) return false;

        Message message = (Message) o;

        return new EqualsBuilder()
                .append(id, message.id)
                .append(isViewed, message.isViewed)
                .append(title, message.title)
                .append(content, message.content)
                .append(sendFrom, message.sendFrom)
                .append(sendTo, message.sendTo)
                .append(sendTime, message.sendTime)
                .append(viewTime, message.viewTime)
                .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .append(id)
                .append(title)
                .append(content)
                .append(sendFrom)
                .append(sendTo)
                .append(sendTime)
                .append(viewTime)
                .append(isViewed)
                .toHashCode();
    }
}
